import logging
import re

"""将日志消息添加到列表中"""


class LogHandler(logging.Handler):
    def __init__(self):
        super().__init__()
        self.logs = []  # 创建一个列表，用于存储日志消息

    def emit(self, record):
        log_message = self.format(record)
        log_message = re.sub(r'\x1b\[[0-9;]*m', '', log_message)
        self.logs.append(log_message)
